package cn.cmdr.service.ServiceImpl;

import cn.cmdr.mapper.OrderMapper;
import cn.cmdr.pojo.Order;
import cn.cmdr.service.OrderService;
import cn.cmdr.vo.OrderVo;
import cn.cmdr.vo.PageVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;
@Service("orderService")
public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements OrderService {
    @Resource
    private OrderMapper orderMapper;
    @Override
    public List<Order> getOrderList() {
        return orderMapper.selectList(null);
    }

    @Override
    public PageVo getPageOrderList(Integer pageNo, Integer pageSize, OrderVo orderVo) {
        Page page = new Page();
        page.setSize(pageSize);
        page.setCurrent(pageNo);
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.like(!StringUtils.isEmpty(orderVo.getOrderSn()),"order_sn",orderVo.getOrderSn())
                .eq(orderVo.getPayType()!=null,"pay_type", orderVo.getPayType())
                .eq(orderVo.getStatus()!=null,"status", orderVo.getStatus())
                .gt(orderVo.getStime()!=null,"birthday",orderVo.getStime())
                .lt(orderVo.getEtime()!=null,"birthday",orderVo.getEtime());
        IPage<Order> iPage = super.page(page,queryWrapper);
        return new PageVo(iPage.getRecords(),iPage.getTotal());
    }

    @Override
    public Order getOrderById(Integer id) {
        return orderMapper.selectById(id);
    }

    @Override
    public void updateOrder(Order order) {
        orderMapper.updateById(order);
    }

    @Override
    public void delOrder(Integer id) {
        orderMapper.deleteById(id);
    }

    @Override
    public int getCount(Integer status) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq(status!=null,"status",status);
        int count = super.count(queryWrapper);
        return count;
    }

    @Override
    public void pdel(Integer[] id) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.in("id",id);
        orderMapper.delete(queryWrapper);
    }
}
